﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using Akiha.Core;
using ESRI.ArcGIS.Geometry;

using System.Runtime.InteropServices;

using ESRI.ArcGIS.esriSystem;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList;



namespace GIS.GeoDataManage.Dialogs
{
    //TreeList的专为AO设计的扩展类，用于显示AO的诸多数据
    class TreeListExtensionForAO:TreeList
    {

        
         private IMap m_Map=null;
         //当前选择的node
         //private TreeListNode m_Node = null;


         public TreeListExtensionForAO()
         {
             initTreeList();
         }

         public TreeListExtensionForAO(IMap pMap)
         {
             m_Map = pMap;
             //添加初始列信息
             initTreeList();
         }



         public IMap Map { get{return m_Map;} set{m_Map=value;} }
 
        

        //初始化treelist，增加列
        private void initTreeList()
        {
            //object列不显示
            string[] strCol = { "引用", "图层名称" };
            for (int i =0; i < 2; i++)
            {
                TreeListColumn treeCol = this.Columns.Add();
                treeCol.Caption = strCol[i];
                treeCol.VisibleIndex = 0 == i ? -1 : i - 1;
            }
        }


        //载入地图的图层到list中,手动载入
        public void LoadLayers()
        {

            if (m_Map==null)
            {
                return;
            }
            //重复载入时清理节点。
            this.ClearNodes();         
            List<IFeatureLayer> lstFeaLyr = MapWrapper.GetLayers(m_Map, null);
            this.BeginUnboundLoad();
            foreach (IFeatureLayer pFeaLyr in lstFeaLyr)
            {
                if (pFeaLyr.FeatureClass == null)
                {
                    continue;
                }
                
               
                TreeListNode node = this.AppendNode(new object[] { pFeaLyr, pFeaLyr.Name }, null);
                node.HasChildren = false;
                
            }
            this.EndUnboundLoad();

        }



        //获取当前选择的图层引用
        public IFeatureLayer GetSelLayer()
        {
           TreeListNode selTreeListNode = this.FocusedNode;
           if (selTreeListNode!=null)
           {
               return (IFeatureLayer)selTreeListNode.GetValue(0);
           }
           return null;  
            
         



        }        

        //获取多选的图层引用
        public List<IFeatureLayer> GetSelLayers()
        {
            return null;
        }





        
    }
}
